package me.zxk.qwert_poetry.dto.response;


import lombok.Data;

@Data
public class Response<T> {
    private int code;
    private String msg;
    private T data;

    public Response(String message, int errorCode) {
        this.msg = message;
        this.code = errorCode;
    }

    public Response(String message, int errorCode, T data) {
        this.msg = message;
        this.code = errorCode;
        this.data = data;
    }

    public static <T> Response<T> ok(T data) {
        return new Response<T>("ok", 0, data);
    }

    public static <Void> Response<Void> ok() {
        return new Response<>("ok", 0, null);
    }

    public static <T> Response<T> error(String message, int errorCode) {
        return new Response<T>(message, errorCode);
    }

    @Override
    public String toString() {
        // JSON
        return "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"data\":" + data + "}";
    }
}
